package com.sx.gongzhong.adapter;


import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.gongzhong.R;
import com.sx.gongzhong.model.DefendRoadBean;
import com.sx.gongzhong.net.ServiceFactory;
import com.sx.gongzhong.utils.BaseUtil;

import java.util.List;

/**
 * Created by XZY on 2017/12/28
 * 全民护路
 */

public class DefendRoadListAdapter extends BaseQuickAdapter<DefendRoadBean,BaseViewHolder> {

    private Context context;

    public DefendRoadListAdapter(Context context, @LayoutRes int layoutResId,
                                 @Nullable List<DefendRoadBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, DefendRoadBean item) {
        helper.setText(R.id.tv_Num,"编号:"+item.getProtectionNum());
        helper.setText(R.id.tv_Content,"  "+item.getContent());
        if (item.getReporter() != null){
            helper.setText(R.id.tv_Name,item.getReporter().getName());
            if (!BaseUtil.isEmpty(item.getReporter().getHeaderUrl())){
                Glide.with(context).load(ServiceFactory.getUrl(item.getReporter().getHeaderUrl()))
                        .apply(new RequestOptions().centerCrop().circleCrop().
                                placeholder(R.mipmap.img_head_58).error(R.mipmap.img_head_58))
                        .into((ImageView)helper.getView(R.id.im_Head));
            }else {
                helper.setImageResource(R.id.im_Head,R.mipmap.img_head_58);
            }
        }else {
            helper.setImageResource(R.id.im_Head,R.mipmap.img_head_58);
        }
        helper.setText(R.id.tv_Time,item.getReportTime());
        helper.setText(R.id.tv_Look,item.getReadTimes()+"");

        TextView tvState=helper.getView(R.id.tv_State);
       if ("to_be_solved".equals(item.getHandleStatus())){//待处理
           tvState.setText("待处理");
           tvState.setBackgroundResource(R.drawable.shape_cff5b5b_12bgd);
       }else {//已解决
           tvState.setText("已解决");
           tvState.setBackgroundResource(R.drawable.shape_green_corner_50);
       }
       ImageView imageView=helper.getView(R.id.imageView);
       if (item.getFiles()!=null&&item.getFiles().size()>0){
           Glide.with(context).load(ServiceFactory.getUrl(item.getFiles().get(0).getPath()))
                   .apply(new RequestOptions().centerCrop().
                           placeholder(R.mipmap.img_fail).error(R.mipmap.img_fail))
                   .into(imageView);
       }else {
           imageView.setVisibility(View.GONE);
       }
    }


}
